package com.solidtrust.crawler.model;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import com.solidtrust.crawler.framework.IUrlOverrider;

public class PageSource {
	
	private IUrlOverrider urlOverrider;

	protected String url;
	
	protected String name;
	
	protected String id;
	
	protected Map<String, String> attributes = new HashMap<>();

	public String getUrl() {
		if(urlOverrider == null){
			return url;
		}
		return urlOverrider.getUrl(url);
	}
	
	public String getOriginalUrl(){
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, String> getAttributes() {
		return attributes;
	}

	public void setAttributes(Map<String, String> attributes) {
		this.attributes = attributes;
	}
	
	public void setUrlOverrider(IUrlOverrider urlOverrider) {
		this.urlOverrider = urlOverrider;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public IUrlOverrider getUrlOverrider() {
		return urlOverrider;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof PageSource){
			PageSource that = (PageSource) obj;
			return that.url.equals(this.url);
		}
		return false;
	}
	
	@Override
	public String toString() {
		return MessageFormat.format("PageSource[name={0}, url={1}]", name, url);
	}
}
